package cq.zhcqk.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;
import java.util.Map;

import cq.zhcqk.R;
import cq.zhcqk.util.Common;
import cq.zhcqk.util.ImageLoaderHelper;

/**
 * Created by zhangle on 2018/3/7.
 */
public class AxstDetailAdapter  extends BaseAdapter {
    List<Map<String,Object>> list;
    Context context;
    public AxstDetailAdapter(Context context, List<Map<String, Object>> list){
        this.list = list;
        this.context = context;
    }
    @Override
    public int getCount() {
        return list ==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final viewHolder holder;
        if(convertView == null){
            holder = new viewHolder();
            convertView = View.inflate(context, R.layout.item_axst_detail,null);
            holder.img = (ImageView) convertView.findViewById(R.id.img);
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.price = (TextView) convertView.findViewById(R.id.price);
            holder.num = (TextView) convertView.findViewById(R.id.num);
            convertView.setTag(holder);
        }else{
            holder = (viewHolder) convertView.getTag();
        }

        Map<String, Object> info = list.get(position);
        holder.name.setText(info.get("dishName")+"");
        holder.price.setText("¥ "+info.get("dishMoney"));
        holder.num.setText("x"+info.get("dishNum"));
        ImageLoader.getInstance().displayImage(Common.URL + info.get("dishPic")+"", holder.img, ImageLoaderHelper.getOptionsDf());
        return convertView;
    }

    private class viewHolder{
        private ImageView img;
        private TextView name;
        private TextView price;
        private TextView num;
    }
}
